Open
Conversation
On line 97 , `0 <= (j)` is always `true` so removed that too :)
Quuxplusone
requested changes
Jan 29, 2022
| #define _utringbuffer_real_idx(a,j) ((a)->f ? ((j) + (a)->i) % (a)->n : (j)) | ||
| #define _utringbuffer_internalptr(a,j) ((void*)((a)->d + ((a)->icd.sz * (j)))) | ||
| #define utringbuffer_eltptr(a,j) ((0 <= (j) && (j) < utringbuffer_len(a)) ? _utringbuffer_internalptr(a,_utringbuffer_real_idx(a,j)) : NULL) | ||
| #define utringbuffer_eltptr(a,j) (((j) < utringbuffer_len(a)) ? _utringbuffer_internalptr(a,_utringbuffer_real_idx(a,j)) : NULL) |
Collaborator
There was a problem hiding this comment.
Here j could certainly be negative if it were, for example, -1, or an int that happened to have the value -1.
If you're doing this to work around a compiler warning, please file a bug/issue with a minimal compilable example that demonstrates the warning and maybe we can find a way to silence it.
Author
There was a problem hiding this comment.
Hi, here's the output from the compiler and seem to disagree with that assertion but it might be wrong.
swuniq.c: In function ‘lookup’:
uthash/src/utringbuffer.h:97:38: warning: comparison of unsigned expression >= 0 is always true [-Wtype-limits]
97 | #define utringbuffer_eltptr(a,j) ((0 <= (j) && (j) < utringbuffer_len(a)) ? _utringbuffer_internalptr(a,_utringbuffer_real_idx(a,j)) : NULL)
| ^~
swuniq.c:133:25: note: in expansion of macro ‘utringbuffer_eltptr’
133 | XXH64_hash_t *item = utringbuffer_eltptr(rbuffer, i);
| ^~~~~~~~~~~~~~~~~~~
swuniq.c: In function ‘main’:
uthash/src/utringbuffer.h:46:12: warning: conversion from ‘size_t’ {aka ‘long unsigned int’} to ‘unsigned int’ may change value [-Wconversion]
46 | (a)->n = (_n); \
| ^
uthash/src/utringbuffer.h:76:3: note: in expansion of macro ‘utringbuffer_init’
76 | utringbuffer_init(a, n, _icd); \
| ^~~~~~~~~~~~~~~~~
swuniq.c:176:2: note: in expansion of macro ‘utringbuffer_new’
176 | utringbuffer_new(history, window_size, &ut_xxh64_hash_t_icd);
| ^~~~~~~~~~~~~~~~
uthash/src/utringbuffer.h:97:38: warning: comparison of unsigned expression >= 0 is always true [-Wtype-limits]
97 | #define utringbuffer_eltptr(a,j) ((0 <= (j) && (j) < utringbuffer_len(a)) ? _utringbuffer_internalptr(a,_utringbuffer_real_idx(a,j)) : NULL)
| ^~
uthash/src/utringbuffer.h:55:23: note: in expansion of macro ‘utringbuffer_eltptr’
55 | (a)->icd.dtor(utringbuffer_eltptr(a, _ut_i)); \
| ^~~~~~~~~~~~~~~~~~~
uthash/src/utringbuffer.h:69:3: note: in expansion of macro ‘utringbuffer_clear’
69 | utringbuffer_clear(a); \
| ^~~~~~~~~~~~~~~~~~
uthash/src/utringbuffer.h:80:3: note: in expansion of macro ‘utringbuffer_done’
80 | utringbuffer_done(a); \
| ^~~~~~~~~~~~~~~~~
swuniq.c:189:2: note: in expansion of macro ‘utringbuffer_free’
189 | utringbuffer_free(history);
| ^~~~~~~~~~~~~~~~~
uthash/src/utringbuffer.h:97:38: warning: comparison of unsigned expression >= 0 is always true [-Wtype-limits]
97 | #define utringbuffer_eltptr(a,j) ((0 <= (j) && (j) < utringbuffer_len(a)) ? _utringbuffer_internalptr(a,_utringbuffer_real_idx(a,j)) : NULL)
| ^~
uthash/src/utringbuffer.h:60:23: note: in expansion of macro ‘utringbuffer_eltptr’
60 | (a)->icd.dtor(utringbuffer_eltptr(a, _ut_i)); \
| ^~~~~~~~~~~~~~~~~~~
uthash/src/utringbuffer.h:69:3: note: in expansion of macro ‘utringbuffer_clear’
69 | utringbuffer_clear(a); \
| ^~~~~~~~~~~~~~~~~~
uthash/src/utringbuffer.h:80:3: note: in expansion of macro ‘utringbuffer_done’
80 | utringbuffer_done(a); \
| ^~~~~~~~~~~~~~~~~
swuniq.c:189:2: note: in expansion of macro ‘utringbuffer_free’
189 | utringbuffer_free(history);
| ^~~~~~~~~~~~~~~~~
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On line 97 ,
0 <= (j)is alwaystrueso removed that too :)